/**
  ******************************************************************************
  * @file           : sensor.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */	
#ifndef __SI2C_COMM_H
#define __SI2C_COMM_H

#include <stdint.h>

#define SI2C_ACK                0
#define SI2C_NACK               1

/* Sensor power */
#define SENSOR_PWR_PIN          GPIO_PIN_7
#define SENSOR_PWR_GPIO_PORT    GPIOB
#define sensor_pwr_h()          (SENSOR_PWR_GPIO_PORT->BSRR = SENSOR_PWR_PIN)
#define sensor_pwr_l()          (SENSOR_PWR_GPIO_PORT->BRR  = SENSOR_PWR_PIN)

/* SHT30 IO */
#define SHT30_SDA_PIN           GPIO_PIN_9         
#define SHT30_SDA_GPIO_PORT     GPIOB                       
#define sht30_sda_h()           (SHT30_SDA_GPIO_PORT->BSRR = SHT30_SDA_PIN) 
#define sht30_sda_l()           (SHT30_SDA_GPIO_PORT->BRR  = SHT30_SDA_PIN)
#define sht30_sda_r()           (SHT30_SDA_GPIO_PORT->IDR  & SHT30_SDA_PIN)

#define SHT30_SCL_PIN           GPIO_PIN_8                
#define SHT30_SCL_GPIO_PORT     GPIOB                    
#define sht30_scl_h()           (SHT30_SCL_GPIO_PORT->BSRR = SHT30_SCL_PIN)
#define sht30_scl_l()           (SHT30_SCL_GPIO_PORT->BRR  = SHT30_SCL_PIN)

/* SGP30 IO */
#define SGP30_SDA_PIN           GPIO_PIN_2         
#define SGP30_SDA_GPIO_PORT     GPIOC
#define sgp30_sda_h()           (SGP30_SDA_GPIO_PORT->BSRR = SGP30_SDA_PIN) 
#define sgp30_sda_l()           (SGP30_SDA_GPIO_PORT->BRR  = SGP30_SDA_PIN)
#define sgp30_sda_r()           (SGP30_SDA_GPIO_PORT->IDR  & SGP30_SDA_PIN)

#define SGP30_SCL_PIN           GPIO_PIN_1                
#define SGP30_SCL_GPIO_PORT     GPIOC
#define sgp30_scl_h()           (SGP30_SCL_GPIO_PORT->BSRR = SGP30_SCL_PIN)
#define sgp30_scl_l()           (SGP30_SCL_GPIO_PORT->BRR  = SGP30_SCL_PIN)

/* SDP810 IO */
#define SDP810_SDA_PIN          GPIO_PIN_11
#define SDP810_SDA_GPIO_PORT    GPIOB
#define sdp810_sda_h()          (SDP810_SDA_GPIO_PORT->BSRR = SDP810_SDA_PIN) 
#define sdp810_sda_l()          (SDP810_SDA_GPIO_PORT->BRR  = SDP810_SDA_PIN)
#define sdp810_scl_r()          (SDP810_SDA_GPIO_PORT->IDR  & SDP810_SDA_PIN)

#define SDP810_SCL_PIN          GPIO_PIN_10
#define SDP810_SCL_GPIO_PORT    GPIOB
#define sdp810_scl_h()          (SDP810_SCL_GPIO_PORT->BSRR = SDP810_SCL_PIN)
#define sdp810_scl_l()          (SDP810_SCL_GPIO_PORT->BRR  = SDP810_SCL_PIN)


extern void sI2c_IOPowerReset(void);

extern void sI2C_ResetI2C(void);
extern uint8_t Sht30_ResetCmd(void);
extern uint8_t Sht30_GetSingleMeasure(volatile float *temperature, volatile float *humidity);

extern uint8_t Sgp30_ReInit(void);
extern void Sgp30_ResetCmd(void);
extern uint8_t Sgp30_GetSingleMeasure(volatile uint16_t *CO2, volatile uint16_t *TVOC);

extern uint8_t Sdp810_ReInit(void);
extern void Sdp810_ResetCmd(void);
extern uint8_t Sdp810_GetSingleMeasure(volatile int16_t *pa);

extern uint8_t sensor_crc8(const uint8_t* value, uint8_t init);

#endif  /* __SI2C_COMM_H */
